package com.sf.util;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class PageResult {
    // 当前页
    private Integer currentPage;   // 可以从queryObject 获取到
    // 每页显示数据
    private Integer pageSize;      //  默认值就是5
    // 分页完以后列表
    private List data;
    //总记录数
    private Integer totalCount;

    // 上一页
    private Integer prevPage;
    // 下一页
    private Integer nextPage;
    // 总页数
    private Integer totalPage;



    public PageResult(Integer currentPage, Integer pageSize, List data, Integer totalCount) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.data = data;
        this.totalCount = totalCount;

        if(totalCount >0){
            this.prevPage = this.currentPage -1 >=1 ? this.currentPage -1 : 1;
            this.totalPage = this.totalCount % this.pageSize == 0 ?
                    this.totalCount/this.pageSize: this.totalCount/this.pageSize +1;
            this.nextPage = this.currentPage + 1 <= this.totalPage ? this.currentPage +1 : totalPage;
        }
    }




}
